package util;
import java.util.List;

import model.Barra;



public class SortUtil {
	

	public static void sort(Barra[] barra) 
	{
		int i = 1;
		while (i < barra.length) 
		{
			if (i == 0 || barra[i - 1].compareTo(barra[i]) <= 0) 
			{
				i++;
			} 
			else 
			{
				swap(barra,i - 1, i);
				i--;
			}
		}
	}

	public static  void reverse(Barra[] barra) 
	{
		int i = 1;
		while (i < barra.length)
		{
			if (i == 0 || barra[i - 1].compareTo(barra[i]) >= 0) 
			{
				i++;
			} 
			else 
			{
				swap(barra,i - 1, i);
				i--;
			}
		}
	}
	
	/**
	 * Swap two ranks in array of type T
	 * @param <T>
	 * @param arr :: T[]
	 * @param i :: int
	 * @param j :: int
	 */
	public static <T> void swap(T[] arr, int i, int j) 
	{
		T temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
		Util.incNumTrocas();
	}

	public static <T> void swap(List<T> list, int i, int j) 
	{
		T temp = list.get(i);
		list.set(i, list.get(j));
		list.set(j, temp);
	}

}
